class VolatileReRange {

    int a = 0;
    boolean flag = false;

    public static void main(String[] args) {
        final VolatileReRange volatileReRange = new VolatileReRange();
        new Thread(new Runnable() {
            @Override
            public void run() {
                volatileReRange.testA();
            }
        }, "A").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                volatileReRange.testB();
            }
        }, "B").start();
    }

    public void testA() {
        //语句1
        a = 1;
        //语句2
        flag = true;
    }

    public void testB() {
        if (flag) {
            a = a + 5;
            System.out.println(a);
        }
    }
}